package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.dto.SysRegisterDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.pojo.SysUser;
import com.nineclock.system.service.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据用户名或手机号查询用户
     * @param username 用户名或手机号
     * @return
     */
    @GetMapping("/query")
    public Result<SysUserDTO> queryUser(@RequestParam String username){
        SysUserDTO userDTO = sysUserService.queryUser(username);
        return Result.success(userDTO);
    }

    /**
     * 接口名称：用户注册: 注册用户
     * 接口路径：POST/sys/user/register
     */
    @ApiOperation("用户注册: 注册用户")
    @PostMapping("register")
    public Result register(SysRegisterDTO sysRegisterDTO){
        sysUserService.register(sysRegisterDTO);
        return Result.success();
    }
}